package com.tuanzi.blog.base.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Enumeration;

/**
 * 负责页面的统一跳转
 */

@Controller
public class ViewController {

    //localhost:8080/blog/add?name=xxxx&title=xxx
    //localhost:8080/blog/add/zhangsan/旅游  workbench/article/index
    @RequestMapping(value = "/toView/{firstView}/{secondView}/{thirdView}")
    public String toView(@PathVariable(value = "firstView") String firstView,
                         @PathVariable(value = "secondView") String secondView,
                         @PathVariable(value = "thirdView") String thirdView,
                         HttpServletRequest request){

        //获取所有参数的名字
        Enumeration<String> names = request.getParameterNames();
        while (names.hasMoreElements()){
            String name = names.nextElement();
            String value = request.getParameter(name);
            System.out.println("name："+name+"value："+value);
            //设置到request域中
            request.setAttribute(name,value);
        }

        //File.separator：\
        return firstView + File.separator + secondView + File.separator + thirdView;
    }

}
